package cn.wj.school.cloud.service;

import cn.wj.school.cloud.dao.SySchoolMapper;
import cn.wj.school.cloud.dto.PageResponse;
import cn.wj.school.cloud.dto.SySchoolDTO;
import cn.wj.school.cloud.dto.condition.SchoolCondition;
import cn.wj.school.cloud.model.SySchool;
import cn.wj.school.cloud.utils.BeanCopyUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Author: yueding
 * @Description: 学校服务
 * @Date: Created in 16:38 2019/1/15
 * @Modified By: yueding Copyright(c) cai-inc.com
 */
@Service
public class SchoolServiceImpl implements SchoolService {

    @Autowired
    private SySchoolMapper sySchoolMapper;

    /**
     * 分页查询学校
     *
     * @param condition
     * @return
     */
    @Override
    public PageResponse<SySchoolDTO> getSchoolsByCondition(SchoolCondition condition) {
        if (condition == null) {
            condition = new SchoolCondition();
        }
        long count = sySchoolMapper.selectCountByCondition(condition);
        if (count > 0) {
            return new PageResponse(count,
                    BeanCopyUtil.genBeanList(sySchoolMapper.selectListByCondition(condition), SySchoolDTO.class));
        }
        return new PageResponse(0, Collections.emptyList());
    }
}
